
package jpoco.client;

import java.util.*;

@SuppressWarnings("serial")
public class QueryParameters implements java.io.Serializable
{
	public static final String SORT_ORDER_ASCENDING = "ascending";
	public static final String SORT_ORDER_DESCENDING = "descending";
	
	private long updatedSince = -1;
	private String filterBy;
	private List<FilterOp> filterOperations = new ArrayList<FilterOp>();
	private String sortBy;
	private String sortOrder;
	
	public long getUpdatedSince()
	{
		return updatedSince;
	}
	
	public void setUpdatedSince(long since)
	{
		this.updatedSince = since;
	}
	
	public String getFilterBy()
	{
		return filterBy;
	}
	
	public void setFilterBy(String s)
	{
		this.filterBy = s;
	}
	
	public List<FilterOp> getFilterOperations()
	{
		return filterOperations;
	}
	
	public void addFilterOperation(FilterOp operation)
	{
		this.filterOperations.add(operation);
	}

	public Map<String, String> getUrlParamMap()
	{
		Map<String, String> map = new HashMap<String, String>();

		for (FilterOp filter : getFilterOperations())
		{
			map.putAll(filter.getParameterMap());
		}
		
		if (getUpdatedSince() != -1)
		{
			map.put("updatedSince", "" + XmlDateTime.toString(getUpdatedSince()));
		}
		
		if (this.getSortBy() != null)
		{
			map.put("sortBy", getSortBy());
		}
		
		if (this.getSortBy() != null)
		{
			map.put("sortBy", getSortBy());
		}
		
		if (this.getSortOrder() != null)
		{
			map.put("sortOrder", getSortOrder());
		}
		
		return map;
	}

	public String getSortBy()
	{
		return sortBy;
	}

	public void setSortBy(String s)
	{
		this.sortBy = s;
	}

	public String getSortOrder()
	{
		return sortOrder;
	}

	/**
	 * 
	 * @param order  QueryParameters.SORT_ORDER_ASCENDING or QueryParameters.SORT_ORDER_DESCENDING
	 * 
	 */
	public void setSortOrder(String order)
	{
		this.sortOrder = order;
	}
	
	
}
